package com.loopy.tomcat.servlet;

import com.loopy.tomcat.http.loopyRequest;
import com.loopy.tomcat.http.loopyResponse;
import com.loopy.tomcat.utils.WebUtils;

import java.io.IOException;
import java.io.OutputStream;

public class loopyCalServlet extends loopyhttpSevlet {
    @Override
    public void doGet(loopyRequest request, loopyResponse response) {
        String s1 = request.getParameter("num1");
        String s2 = request.getParameter("num2");
        int num1 = WebUtils.parseInt(s1, 0);
        int num2 = WebUtils.parseInt(s2, 0);
        int result = num1 + num2;
        OutputStream outputStream = response.getOutputStream();
        String resMes = response.resHeader + "<h1>" + num1 + "+" + num2 + "=" + result + "MyTomcat03</h1>";
        try {
            outputStream.write(resMes.getBytes());
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void doPost(loopyRequest request, loopyResponse response) {
        doGet(request, response);
    }

    @Override
    public void init() throws Exception {

    }

    @Override
    public void destroy() {

    }
}
